<template>
  <div v-loading="loading">
    <queryHead v-if="head" :explain="explain" :result="msg" :time="time" :price="price" @query="query"/>
    <div v-if="lock" style="background-color: #fafafa;padding: 5px;border-radius: 5px">
      <i class="el-icon-s-check">
        <label>建议评分</label>
      </i>
      <el-result
        :icon="dttz.Rule.result.final_decision == 'Accept'?'success':dttz.Rule.result.final_decision == 'Reject'?'error':dttz.Rule.result.final_decision == 'Review'?'warning':'extra'"
        :title="dttz.Rule.result.final_decision == 'Accept'?'通过':dttz.Rule.result.final_decision == 'Reject'?'拒绝':dttz.Rule.result.final_decision == 'Review'?'复议':'暂无建议'"
        subTitle="依据命中风险点提供风险建议">
      </el-result>
      <div style="margin-bottom: 20px">
        风险点预警评分：{{ 100 - dttz.Rule.result.final_weight }}分 (总分100,分数越高越安全)
        <el-progress :text-inside="true" :stroke-width="20" :format="format"
                     :percentage="100-numDelivery(dttz.Rule.result.final_weight)"/>
      </div>

      <i class="el-icon-s-check">
        <label>命中风险点</label>
      </i>
      <div>
        <el-row>
          <template v-if="dttz.Flag.ruleexecutionlimited == '1'">
            <el-col :xs="12" :sm="8" :lg="4"
                    v-for="(objValue,key,index) of dttz.Rule.hit_rules.ruleexecutionlimited">
              <div :key="index">
                <div class="dtcxbg-box">
                  <h6>{{ objValue.name_rule }}</h6>
                  <div>
                    <label>置信度:{{ objValue.weight }}%</label>
                  </div>
                </div>
              </div>
            </el-col>
          </template>

          <template v-if="dttz.Flag.rulespeciallist_c == '1'">
            <el-col :xs="12" :sm="8" :lg="4"
                    v-for="(objValue,key,index) of dttz.Rule.hit_rules.rulespeciallist_c">
              <div class="dtcxbg">
                <div class="dtcxbg-box">
                  <h6>{{ objValue.name_rule }}</h6>
                  <div>
                    <label>置信度:{{ objValue.weight }}%</label>
                  </div>
                </div>
              </div>
            </el-col>
          </template>

          <template v-if="dttz.Flag.ruleapplyloan == '1'">
            <el-col :xs="12" :sm="8" :lg="4"
                    v-for="(objValue,key,index) of dttz.Rule.hit_rules.ruleapplyloan">
              <div class="dtcxbg">
                <div class="dtcxbg-box">
                  <h6>{{ objValue.name_rule }}</h6>
                  <div>
                    <label>置信度:{{ objValue.weight }}%</label>
                  </div>
                </div>
              </div>
            </el-col>
          </template>
          <p
            v-show="dttz.Flag.ruleexecutionlimited != '1' && dttz.Flag.rulespeciallist_c != '1' && dttz.Flag.ruleapplyloan != '1'">
            未命中风险点数据</p>
        </el-row>
      </div>

      <div style="text-align: center;margin-top: 20px">
        手机号与身份证合计多次申请信贷情况
      </div>
      <i class="el-icon-s-check">
        <label>银行机构</label>
      </i>
      <table class="sfhy" style="margin-bottom: 12px">
        <thead>
        <tr>
          <th>申请次数 | 申请机构数</th>
          <th>近7天</th>
          <th>近15天</th>
          <th>近1个月</th>
          <th>近3个月</th>
          <th>近6个月</th>
          <th>近12个月</th>
        </tr>
        </thead>
        <tbody>
        <tr v-for="(item, key) in dttz.ApplyLoanStr.yhjg">
          <td>
            <template v-if="key==0">合计申请</template>
            <template v-else-if="key==1">在周末</template>
            <template v-else-if="key==2">在夜间</template>
            <template v-else-if="key==3">在网络零售银行</template>
            <template v-else-if="key==4">在传统银行</template>
          </td>
          <td>{{ item[0] }}</td>
          <td>{{ item[1] }}</td>
          <td>{{ item[2] }}</td>
          <td>{{ item[3] }}</td>
          <td>{{ item[4] }}</td>
          <td>{{ item[5] }}</td>
        </tr>
        </tbody>
      </table>

      <i class="el-icon-s-check">
        <label>非银行机构</label>
      </i>
      <table class="sfhy " style="margin-bottom: 12px">
        <thead>
        <tr>
          <th>申请次数 | 申请机构数</th>
          <th>近7天</th>
          <th>近15天</th>
          <th>近1个月</th>
          <th>近3个月</th>
          <th>近6个月</th>
          <th>近12个月</th>
        </tr>
        </thead>
        <tbody>
        <tr v-for="(item, key) in dttz.ApplyLoanStr.fyhjg">
          <td>
            <template v-if="key==0">合计申请</template>
            <template v-else-if="key==1">在周末</template>
            <template v-else-if="key==2">在夜间</template>
            <template v-else-if="key==3">小贷</template>
            <template v-else-if="key==4">消费类分期</template>
            <template v-else-if="key==5">现金类分期</template>
            <template v-else-if="key==6">其他</template>
            <template v-else-if="key==7">改制机构</template>
            <template v-else-if="key==8">代偿类分期</template>
            <template v-else-if="key==9">持牌小贷机</template>
            <template v-else-if="key==10">持牌消费金融</template>
            <template v-else-if="key==11">持牌网络小贷</template>
            <template v-else-if="key==12">持牌融资租赁</template>
            <template v-else-if="key==13">持牌汽车金融</template>
          </td>
          <td>{{ item[0] }}</td>
          <td>{{ item[1] }}</td>
          <td>{{ item[2] }}</td>
          <td>{{ item[3] }}</td>
          <td>{{ item[4] }}</td>
          <td>{{ item[5] }}</td>
        </tr>
        </tbody>
      </table>

      <i class="el-icon-s-check">
        <label>分类借贷统计</label>
      </i>
      <table class="sfhy" style="margin-bottom: 12px">
        <thead>
        <tr>
          <th>申请次数 | 申请机构数</th>
          <th>近7天</th>
          <th>近15天</th>
          <th>近1个月</th>
          <th>近3个月</th>
          <th>近6个月</th>
          <th>近12个月</th>
        </tr>
        </thead>
        <tbody>
        <tr v-for="(item, key) in dttz.ApplyLoanStr.fljd">
          <td>
            <template v-if="key==0">信用卡（类信用卡）</template>
            <template v-else-if="key==1">线下消费分期</template>
            <template v-else-if="key==2">线下现金分期</template>
            <template v-else-if="key==3">线上小额现金贷</template>
            <template v-else-if="key==4">线上消费分期</template>
            <template v-else-if="key==5">线上现金分期</template>
            <template v-else-if="key==6">汽车金融</template>
            <template v-else-if="key==7">其他</template>
          </td>
          <td>{{ item[0] }}</td>
          <td>{{ item[1] }}</td>
          <td>{{ item[2] }}</td>
          <td>{{ item[3] }}</td>
          <td>{{ item[4] }}</td>
          <td>{{ item[5] }}</td>
        </tr>
        </tbody>
      </table>

      <i class="el-icon-s-check">
        <label>每月综合统计</label>
      </i>
      <table class="sfhy" style="margin-bottom: 12px">
        <thead>
        <tr>
          <th>总体 | 在银行机构 | 在非银机构</th>
          <th>近3个月</th>
          <th>近6个月</th>
          <th>近12个月</th>
        </tr>
        </thead>
        <tbody>
        <tr v-for="(item, key) in dttz.ApplyLoanStr.yftj">
          <td>
            <template v-if="key==0">最小月申请次数</template>
            <template v-else-if="key==1">最大月申请次数</template>
            <template v-else-if="key==2">有申请记录月份数</template>
            <template v-else-if="key==3">申请最小间隔天数</template>
            <template v-else-if="key==4">申请最大间隔天数</template>
            <template v-else-if="key==5">平均每月申请次数(有申请月份平均)</template>
          </td>
          <td>{{ item[0] }}</td>
          <td>{{ item[1] }}</td>
          <td>{{ item[2] }}</td>
        </tr>
        </tbody>
      </table>

      <i class="el-icon-s-check">
        <label>失信情况总览</label>
      </i>
      <div>
        <template v-for="(objValue,key,index) of dttz.ExecutionLimited">
          <div class="sxbt" v-if="key.substring(0,2) == 'xg'">法院限高被执行人</div>
          <el-descriptions v-if="key.substring(0,2) == 'xg'" :column="5" border size="mini">
            <el-descriptions-item label="姓名">{{ objValue.iname }}</el-descriptions-item>
            <el-descriptions-item label="性别">{{ objValue.sexname }}</el-descriptions-item>
            <el-descriptions-item label="年龄">{{ objValue.age }}</el-descriptions-item>
            <el-descriptions-item label="地域">{{ objValue.areaname }}</el-descriptions-item>
            <el-descriptions-item label="案号">{{ objValue.casecode }}</el-descriptions-item>
            <el-descriptions-item label="执行法院">{{ objValue.courtname }}</el-descriptions-item>
            <el-descriptions-item label="案件状态">{{ objValue.datatype }}</el-descriptions-item>
            <el-descriptions-item label="发布时间">{{ objValue.publishdate }}</el-descriptions-item>
            <el-descriptions-item label="立案时间">{{ objValue.regdate }}</el-descriptions-item>
          </el-descriptions>

          <div class="sxbt" v-if="key.substring(0,2) == 'sx'">法院失信被执行人</div>
          <el-descriptions v-if="key.substring(0,2) == 'sx'" :column="5" border size="mini">
            <el-descriptions-item label="案号">{{ objValue.casecode }}</el-descriptions-item>
            <el-descriptions-item label="姓名">{{ objValue.iname }}</el-descriptions-item>
            <el-descriptions-item label="性别">{{ objValue.sexname }}</el-descriptions-item>
            <el-descriptions-item label="年龄">{{ objValue.age }}</el-descriptions-item>
            <el-descriptions-item label="企业法人姓名">{{ objValue.buesinessentity }}</el-descriptions-item>
            <el-descriptions-item label="执行法院">{{ objValue.courtname }}</el-descriptions-item>
            <el-descriptions-item label="地域名称">{{ objValue.areaname }}</el-descriptions-item>
            <el-descriptions-item label="标识自然人或企业">{{ objValue.partytypename }}</el-descriptions-item>
            <el-descriptions-item label="执行依据文号">{{ objValue.gistcid }}</el-descriptions-item>
            <el-descriptions-item label="发布时间">{{ objValue.publishdate }}</el-descriptions-item>
            <el-descriptions-item label="立案时间">{{ objValue.regdate }}</el-descriptions-item>
            <el-descriptions-item label="数据类型">{{ objValue.datatype }}</el-descriptions-item>
          </el-descriptions>
        </template>
        <div v-if="Object.keys(dttz.ExecutionLimited).length == 0">
          暂无该项信息
        </div>
      </div>

    </div>
  </div>
</template>
<script>
  import queryHead from "@/views/components/queryHead.vue";
  import {queryRecord, queryData, updateQuery} from "@/api/system/query";
  import {
    disposeAls
  } from '@/utils/options.js';

  export default {
    components: {queryHead},
    name: "dttz",
    props: {
      queryData: {
        required: true,
        type: Object
      },
      price: {
        default: null,
        type: Number
      },
      priceType: {
        default: null,
        type: Boolean
      },
      explain: {
        default: null,
        type: String
      },
      head: {
        default: true,
        type: Boolean
      }
    },
    data() {
      return {
        loading: false,
        lock: false,
        msg: undefined,
        time: undefined,
        dttz: {}
      }
    },
    created() {
      this.loading = true
      queryRecord(this.queryData).then(response => {
        this.disResponse(response)
      })
    },
    methods: {
      query() {
        this.loading = true
        queryData(this.queryData).then(response => {
          this.disResponse(response)
        });
      },
      disResponse(response) {
        // console.log('---dttz---', response)
        if (response.info) {
          this.time = response.time
          const info = JSON.parse(response.info)
          console.log('---info---', info)
          this.msg = info.retmsg
          if (info.retcode == '000000') {
            const retdata = info.retdata
            if (retdata.code == '00') {

              if (retdata.Flag.applyloanstr == '1') {
                retdata.ApplyLoanStr = disposeAls(retdata.ApplyLoanStr)
                this.dttz = retdata
                this.lock = true
              }
              if (retdata.Flag.riskstrategy == '1') {
                const weight = retdata.Rule.result.final_weight
                const decision = retdata.Rule.result.final_decision
                updateQuery({
                  queryId: this.queryData.queryId,
                  score: 100 - parseInt(weight),
                  decision: decision == 'Accept' ? '通过' : decision == 'Reject' ? '拒绝' : decision == 'Review' ? '复议' : '暂无建议'
                })
              }
            } else if (retdata.code == '100002') {
              this.msg += ' 但未匹配到结果(可能无信贷历史)'
              this.$modal.msg('查询成功，但策略配置里全部子产品均未匹配到结果')
            } else {
              this.$modal.msg(this.msg)
            }
          } else {
            this.$modal.msgWarning('查询失败，原因：' + this.msg)
          }
        }
        this.loading = false
      },
      format(percentage) {
        return percentage === 100 ? '满' : `${percentage}分`
      },
      numDelivery(num) {
        let result = parseFloat(num);
        if (isNaN(result)) {
          return 0
        }
        result = Math.round(num * 100) / 100
        return result
      }
    }
  };
</script>
<style scoped>
  .sfhy {
    margin: 0 auto;
    border: 1px solid #ccc;
    width: 100%;
    border-collapse: collapse;
  }

  .sfhy th, td {
    text-align: center;
    padding: 8px 0px;
    color: #909399;
    font-size: 12px;
  }

  th {
    background-color: #f5f5f5;
  }

  td {
    border: 1px solid #ccc;
  }

  .sxbt {
    margin: 10px 0 4px;
  }

  .dtcxbg {
    box-sizing: border-box;
    height: 110px;
    padding: 5px;
  }

  .dtcxbg-box {
    height: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    h6 {
      font-weight: bold;
      color: #66686d;
    }

    label {
      font-size: 26px;
      color: #53a8fe;
    }
  }
</style>
